<template>
  <el-container class="main_con" style="padding-bottom:0px">
   <ufrom @submit="saveData" ref="ufrom">

        <el-form size="medium" label-width="100px">
          <div class="setting_body_item">
            <div class="header">积分抵扣</div>
            <div class="conetnt edit_con">
              <div class="edit_content">
                <el-form-item label="积分抵扣">
                  <el-radio-group v-model="obj.is_open">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>

                <el-form-item label="" v-if="obj.is_open == 1">
                  <div class="fks">
                    积分抵扣比例：
                    <el-input v-model="obj.deduction" style="width:280px;margin-right:10px;margin-left:10px;">
                      <template slot="prepend">
                        1积分抵扣
                      </template>
                      <template slot="append">
                        元
                      </template>
                    </el-input>
                  </div>
                  <div class="tip">
                    1积分最低抵扣0.01元
                  </div>
                </el-form-item>
              </div>
            </div>
          </div>

          <!--  <div class="setting_body_item">
            <div class="header">余额抵扣</div>
            <div class="conetnt edit_con">
              <div class="edit_content">


                <el-form-item label="充值设置">
                  <el-radio-group v-model="obj.configuration.balance_setting">
                    <el-radio :label="1">开启</el-radio>
                    <el-radio :label="0">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>


              </div>
            </div>
          </div> -->
        </el-form>
   </ufrom>
  </el-container>
</template>

<script>
import {getintegral, editintegral} from '@/api/mall/deduction';
export default {
  data() {
    return {
      isLoading: false,
      obj: {
        is_open: 0,
        deduction: 0
      }
    };
  },

  mounted() {
    this.getintegral();
  },
  methods: {
    //获取站点配置数据
    getintegral() {
      getintegral({})
        .then(res => {
          this.isLoading = false;
          if (res.msg) {
            let o = res.msg;
            this.obj = res.msg;
          }
        })
        .catch(e => {
        });
    },
    //保存数据
    saveData() {
      this.isLoading = true;
      if(this.obj.is_open&&!this.obj.deduction>0){
         this.$message.error("积分比例请大于0")
         return false
      }
      let data = {
        deduction:this.obj.deduction,
        is_open: this.obj.is_open,
        get_integral_type: this.obj.get_integral_type,
        get_integral_ratio: this.obj.get_integral_ratio
      };
      editintegral(data)
        .then(res => {
          this.$refs.ufrom.init()
           this.$message.success("修改成功")
          this.getintegral();
        })
        .catch(e => {
          this.$refs.ufrom.init()
        });
    }
  }
};
</script>

